<?php
//on récupère les informations
if (isset($_GET['id'])) {
    $id = htmlentities($_GET['id'], ENT_QUOTES);
    require_once 'include/config.php';
    //Gestion des fiches poissons
    $sql = 'SELECT * FROM `poisson` INNER JOIN `espace_vie` ON `espacevie`=`idvie` WHERE `idpoisson`= ' . $id;
    //$sql = 'SELECT * FROM `poisson` WHERE `idpoisson`= ' . $id;
    $result = mysql_query($sql);
    $data = mysql_fetch_array($result);

    if ((!empty($data['phMin'])) && (!empty($data['phMax']))) {
        $ph = 'Entre ' . $data['phMin'] . ' et ' . $data['phMax'];
    } else {
        $ph = 'Non renseigné';
    }

    if ((!empty($data['thMin'])) && (!empty($data['thMax']))) {
        $gh = 'Entre ' . $data['thMin'] . ' et ' . $data['thMax'];
    } else {
        $gh = 'Non renseigné';
    }

    if ((!empty($data['tMin'])) && (!empty($data['tMax']))) {
        $t = 'Entre ' . $data['tMin'] . '° et ' . $data['tMax'] . '°';
    } else {
        $t = 'Non renseigné';
    }

    if (!empty($data['espacevie'])) {
        $vie = $data['nomvie'];
    } else {
        $vie = 'Non renseigné';
    }

    if (!empty($data['taille'])) {
        $taille = $data['taille'] . 'cm';
    } else {
        $taille = 'Non renseigné';
    }

    if (!empty($data['difficulte'])) {
        switch ($data['difficulte']) {
            case 1 :
                $difficult = '<img src="images/icone/facile.png" width="64px" height="13px" />';
                break;
            case 2 :
                $difficult = '<img src="images/icone/moyen-2.png" width="64px" height="13px" />';
                break;
            case 3 :
                $difficult = '<img src="images/icone/dur-2.png" width="64px" height="13px" />';
                break;
        }
    } else {
        $difficult = 'Non renseigné';
    }

    if (!empty($data['population'])) {
        if ($data['population'] > 1) {
            $population = $data['population'] . ' individus';
        } else {
            $population = $data['population'] . ' individu';
        }
    } else {
        $population = 'Non renseigné';
    }

    if (!empty($data['esperancevie'])) {
        if ($data['esperancevie'] > 1) {
            $esperance = $data['esperancevie'] . 'ans';
        } else {
            $esperance = $data['esperancevie'] . 'an';
        }
    } else {
        $esperance = 'Non renseigné';
    }

    if (!empty($data['reproduction'])) {
        switch ($data['reproduction']) {
            case 1 :
                $reproduction = '<img src="images/icone/facile.png" width="64px" height="13px" />';
                break;
            case 2 :
                $reproduction = '<img src="images/icone/moyen-2.png" width="64px" height="13px" />';
                break;
            case 3 :
                $reproduction = '<img src="images/icone/dur-2.png" width="64px" height="13px" />';
                break;
        }
    } else {
        $reproduction = 'Non renseigné';
    }
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//FR" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr">
    <head>
        <title><?php echo $data['titre']; ?> selon l'Aquarium Anzin</title>
        <meta charset="utf-8" />
        <meta name="description" content="Découvrez ici la fiche poisson détaillée de <?php echo $data['titre']; ?>. Vous découvrirez les éléments essentiel à son habitats, mais aussi la difficulté général du poisosn, et des images en haute résolution." />
        <meta name="keywords" content="poisson,<?php echo $data['titre']; ?>,eau douce, eau mer, eau froide, fiche, aquarium, anzin" />
        <link rel="stylesheet" href="css/style.css" />
        <link rel="icon" href="images/favicon.ico" type="image/x-icon" />
        <link rel="shortcut icon" href="images/favicon.ico" type="image/x-icon" />        
        <!--[if lt IE 8]>
              <div style=' clear: both; text-align:center; position: relative;'>
                <a href="http://windows.microsoft.com/en-US/internet-explorer/products/ie/home?ocid=ie6_countdown_bannercode">
                  <img src="http://storage.ie6countdown.com/assets/100/images/banners/warning_bar_0000_us.jpg" border="0" height="42" width="820" alt="You are using an outdated browser. For a faster, safer browsing experience, upgrade for free today." />
               </a>
             </div>
            <![endif]-->
        <!--[if lt IE 9]>
                        <script src="js/html5.js"></script>
                        <link rel="stylesheet" href="css/ie.css">
                <![endif]-->
    </head>
    <body id="page1">
        <!--==============================header=================================-->
        <?php
        require_once 'include/menu.php';
        ?>
        <!--==============================content====================================-->
        <section id="content">
            <div class="container_24">                
                <div class="wrapper border-vert3">
                    <div class="grid_17" itemscope itemtype = "http://schema.org/CreativeWork">
                        <div class="wrapper">                                                
                            <h1 itemprop = "name"><?php echo htmlspecialchars(stripcslashes($data['titre'])); ?></h1>
                            <em>Nom latin : </em><?php echo htmlspecialchars(stripcslashes($data['nomlatin'])); ?><br />                                                   
                        </div>
                        <div class="wrapper">
                            <div class="grid_5">
                                <em>Ph : </em><?php echo $ph; ?><br />
                                <em>Espace de vie : </em><?php echo $vie; ?><br />
                                <em>Difficulté : </em><?php echo $difficult; ?><br />
                            </div>
                            <div class="grid_5">
                                <em>Gh : </em><?php echo $gh; ?><br />
                                <em>Taille moyenne : </em><?php echo $taille; ?><br />
                                <em>Espérance de vie : </em><?php echo $esperance; ?><br />
                            </div>

                            <div class="grid_5">
                                <em>Température : </em><?php echo $t; ?><br />
                                <em>Population : </em><?php echo $population; ?><br />
                                <em>Reproduction : </em><?php echo $reproduction; ?><br />
                            </div>
                        </div>
                        <div class="wrapper" itemprop = "description">                            
                                <em>Description : </em>
                                <?php
                                //gérer les puces avec tinymce dans la charte graphique qui désactive les puces.
                                $patterns = '/<li>/';
                                if (preg_match('/<ul>/', $data['description'])) {
                                    $replacements = '<li style="list-style: inside disc;margin-left:30px;">';
                                } else {
                                    $replacements = '<li style="list-style: inside decimal;margin-left:30px;">';
                                }
                                echo stripslashes(preg_replace($patterns, $replacements, $data['description']));                                
                                ?>                            
                        </div>
                    </div>                   

                    <div class="grid_6 prefix_1" style="text-align: center;">
                        <?php
                        if (!empty($data['img1'])) {
                            echo '<div class="pro_image_right"><span class="pro_image_style2"><img src="', $data['img1'], '" alt="', $data['titre'], '" ', $data['img1WH'], '  itemprop = "image" /></span></div>';
                        }
                        
                        if (!empty($data['img2'])) {
                            echo '<div class="pro_image_right"><span class="pro_image_style2"><img src="', $data['img2'], '" alt="', $data['titre'], '" ', $data['img2WH'], '  itemprop = "image" /></span></div>';
                        }
                        
                        if (!empty($data['img3'])) {
                            echo '<div class="pro_image_right"><span class="pro_image_style2"><img src="', $data['img3'], '" alt="', $data['titre'], '" ', $data['img3WH'], '  itemprop = "image" /></span></div>';
                        }
                        ?>
                    </div>
                </div>

            </div>
            <!--            <div class="wrapper">
                            <div class="grid_24">
                                <h3>Vous aimerez aussi...</h3>
            <?php
            //On va afficher les 3 phrases les plus proches de celle que l'on vient d'afficher.
//                $query = 'SELECT `idpoisson`,`titre`,`nomlatin`,`description`,`img`, round(MATCH(`nomlatin`) AGAINST ("' . $data['nomlatin'] . '"),2)as similitude FROM `poisson` ORDER BY similitude DESC LIMIT 0,3';
//                echo $query;
//                $sql = mysql_query($query);
//                $result = mysql_query($sql);
//                $ligne=0;                
//                while ($data = mysql_fetch_array($result)) {                    
//                    if ($ligne==0){
//                        echo '<div class="wrapper">';                        
//                    }
//                    echo '<div class = "grid_6">';
//                    echo '<h4>', $data['titre'], '</h4>';
//                    if (!empty($data['img'])) {
//                        echo '<div class="pro_image_left"><span class="pro_image_style2"><img src="images/poisson/', $data['img'], '" alt="', $data['nomlatin'], '"></span></div>';
//                    }
//                    echo '<p>', tronque($data['description'], 100), '</p>';
//                    echo '<a href="fiche-poisson-'.$data['idpoisson'].'.html" class="pro_btn pro_small">Fiche complète</a>';
//                    echo '</div>';
//                    if ($ligne++==3){
//                        $ligne=0;
//                        echo '</div>';
//                    }
//                }   
            ?>
                            </div>
                        </div>            -->
        </section>
        <?php
        require_once 'include/footer.php';
        ?>
    </body>
</html>